<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>PHP File Open/Read/Close</title>
</head>
<body>
<h1>PHP File Open/Read/Close</h1>

<div>
    <h3>PHP Open File - fopen()</h3>
    <?php

    $myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
    echo(fread($myfile, filesize("webdictionary.txt")));
    fclose($myfile);
    ?>
</div>
<div>
    <h3>PHP Read Single Line - fgets()</h3>
    <?php
    $myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
    echo(fgets($myfile));
    echo("<br/>");
    echo(fgets($myfile));
    fclose($myfile);
    ?>
</div>
<div>
    <h3>PHP Check End-Of-File - feof()</h3>
    <?php
    $myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
    //Output one line until end-of-file
    while (!feof($myfile)) {
        echo(fgets($myfile) . "<br/>");
    }
    fclose($myfile);
    ?>
</div>
<div>
    <h3>PHP Read Single Character - fgetc()</h3>
    <?php
    $myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
    //output one character until end-of-file
    while (!feof($myfile)) {
        $char = strtolower(fgetc($myfile));
        if ($char == "a" or $char == "b" or $char == "c" or $char == "d" or $char == "e") {
            echo($char . " | ");
        }
    }
    ?>
</div>
</body>
</html>